package com.niiwoo.civet.trade.enums;

import java.util.Optional;

/**
 * 借款方式
 * Created by dell on 2018/4/23.
 */
public enum  LoanType {
    DQHBFX("到期还本付息",1),
    DEBX("等额本息",2),
    DEBJ("等额本金",3),
    LSBQ("利随本清",4),
    SJSH("随借随还",5);

    private String descript;
    private int val;

    LoanType(String descript,int val){
        this.descript=descript;
        this.val=val;
    }

    public static Optional<LoanType> getLoanTypeByDescript(String descript){
        if(LoanType.DEBJ.descript.equals(descript)){
            return Optional.of(LoanType.DEBJ);
        }else if(LoanType.DEBX.descript.equals(descript)){
            return Optional.of(LoanType.DEBX);
        }else if(LoanType.LSBQ.descript.equals(descript)){
            return Optional.of(LoanType.LSBQ);
        }else if(LoanType.SJSH.descript.equals(descript)){
            return Optional.of(LoanType.SJSH);
        }else if(LoanType.DQHBFX.descript.equals(descript)){
            return Optional.of(LoanType.DQHBFX);
        }else{
            return Optional.empty();
        }
    }

    public static Optional<LoanType> getLoanTypeByVal(int val){
        if(1 == val){
            return Optional.of(LoanType.DQHBFX);
        }else if(2 == val){
            return Optional.of(LoanType.DEBX);
        }else if(3 == val){
            return Optional.of(LoanType.DEBJ);
        }else if(4 == val){
            return Optional.of(LoanType.LSBQ);
        }else if(5 == val){
            return Optional.of(LoanType.SJSH);
        }else{
            return Optional.empty();
        }
    }
}
